<template>
	<view>
		<scroll-view style="height: 1200rpx;width: 750rpx;" scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="0" refresher-background="#EE7B30" @refresherpulling="onPulling" @refresherrefresh="onRefresh" :scroll-top="scrollTop"  @scrolltolower="scrolltolower" :lower-threshold="juli">
			<view v-for="(itme,index) in kehu_list" :key="index" style="width: 694rpx;box-sizing: border-box;padding: 20rpx;border-radius: 30rpx;background: #FFFFFF;margin: 15rpx 0 15rpx 27rpx;justify-content: space-between;align-items: center;display: flex;">
				<view style="display: flex;align-items: center;">
					<view>
						<image :src="itme.map.userinfo.avatar" style="width: 110rpx;height: 110rpx;border-radius: 50%;"></image>
					</view>
					<view style="margin-left: 20rpx;">
						<view style="font-size: 35rpx;font-weight: bold;">{{itme.map.userinfo.nick_name}}</view>
						<view style="font-size: 28rpx;color: #BFBFBF;margin-top: 10rpx;">{{itme.map.userinfo.mobile}}</view>
					</view>
				</view>
				<view>
					<image :src="lao" class="img" v-if="itme.status == 1" @tap="shezhi(itme,'lao')"></image>
					<image :src="xin" class="img" v-if="itme.status == 1" style="margin-left: 5rpx;" @tap="shezhi(itme,'xin')"></image>
					<text style="color: #FF7300;font-size: 30rpx;" v-if="itme.status != 1">{{itme.is_new ? "新客" : "老客"}}</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
				triggered: false,
				juli: 100,
				mechanism_id: "",
				currentPage: 1,
				kehu_list: [],
				biao: 1,
				lao: "http://img.curiousmore.com/71833",
				xin: "http://img.curiousmore.com/398719"
			}
		},
		methods: {
			onRefresh(){
				this.triggered = true
				this.currentPage = 1
				this.kehu_list = []
				this.kehu()
			},
			scrolltolower() {
				if(this.biao == 1){
					this.currentPage++
					this.kehu()
				}else{
					uni.showToast({
						title: "已加载全部",
						icon: "loading"
					})
				}
			},
		async	kehu(){
				uni.showLoading({
					title: "加载中"
				})
				const res = await this.$myRequest({
					url: "/mechanismUser/queryListPage",
					data: {
						mechanism_id: this.mechanism_id,
						// status: 1,
						pageSize: 10,
						currentPage: this.currentPage
					}
				})
				if(res.code == 0){
					if(res.data < 10){
						this.biao = 2
					}else{
						this.biao = 1
					}
					if(this.kehu_list.length == 0){
						this.kehu_list = res.data
					}else{
						this.kehu_list = this.kehu_list.concat(res.data)
					}
				}else{
					uni.showToast({
						title: res.message
					})
				}
				this.triggered = false
				uni.hideLoading()
			},
		async	shezhi(itme,index){
				let can = ""
				if(index == "lao"){
					can = false
				}else{
					can = true
				}
				const res = await this.$myRequest({
					url: "/mechanismUser/update",
					data: {
						id: itme.id,
						is_new: can
					},
					header:{
						'content-type':'application/json'
					},
					methed: "post"
				})
				if(res.code == 0){
					this.kehu_list = []
					this.kehu()
					uni.showToast({
						title: "修改成功"
					})
				}
			}
		},
		onLoad() {
			try{
				this.mechanism_id = uni.getStorageSync('userif_list').mechanism_id
				this.kehu()
			}catch(e){}
		}
	}
</script>
<style lang="scss" scoped>
	.img{
		width: 124rpx;
		height: 50rpx;
	}
</style>